<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
<%
   if(null==request.getSession().getAttribute("user")){
	   request.getRequestDispatcher("login.jsp").forward(request, response);
   }
%>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>Dashboard Template for Bootstrap</title>
<link rel="stylesheet" href="dist/css/bootstrap.min.css">

<script src="dist/js/jquery-3.3.1.min.js"></script>

<link href="css/dashboard.css" rel="stylesheet">
<script
	src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
   .navbar .nav > li:hover .dropdown-menu {
		display: block;
	}
</style>
</head>

<body>

	<nav class="navbar navbar-inverse navbar-fixed-top">
		<div class="container-fluid">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed"
					data-toggle="collapse" data-target="#navbar" aria-expanded="false"
					aria-controls="navbar">
					<span class="sr-only">Toggle navigation</span> <span
						class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<ul class="nav navbar-nav">
					<li class="dropdown">
					    <a class="navbar-brand" href="#">问答系统</a>
						<a style="margin-left: 100px;" href="#" class="dropdown-toggle glyphicon glyphicon-user" data-toggle="dropdown"
						role="button" aria-haspopup="true" aria-expanded="false">欢迎~${user.userName}~登录管理系统<span class="caret"></span></a>
						<ul class="dropdown-menu" style="margin-left: 100px;">
							<li><a href="#">个人信息</a></li>
							<li><a href="#">切换账号</a></li>
							<li><a href="#">退出</a></li>
						</ul>
					</li>
				</ul>
			</div>
			<div id="navbar" class="navbar-collapse collapse">
				<ul class="nav navbar-nav navbar-right">
					<li><a id="imfor" href="#"></a></li>
					<li><a href="#">仪表盘</a></li>
					<li><a href="#">设置</a></li>
					<li><a href="LoginServlet?op=exit">退出</a></li>
					<li id="btnLo"><a id="modal-27331"
						href="#modal-container-27331" role="button" class="btn"
						data-toggle="modal">登录</a></li>
					<li id="btnExit" style="display: none;"><a
						href="${pageContext.request.contextPath}/UserServlet?op=queryPage"
						class="btn">退出</a></li>
					<li><a href="#">帮助</a></li>
				</ul>
				<form class="navbar-form navbar-right">
					<input type="text" class="form-control" placeholder="Search...">
				</form>
			</div>
		</div>
	</nav>

	<div class="container-fluid">
		<div class="row">
			<div class="col-sm-3 col-md-2 sidebar">
				<ul class="nav nav-sidebar">
					<li><a href="index.jsp">首页 <span class="sr-only">(current)</span></a>
					</li>
					<li><a href="qs?op=queryPage">问答信息管理</a></li>
					<li><a href="addQuestion.jsp">增加问答信息</a></li>
					<li><a href="ab?op=queryPage">回答信息管理</a></li>
				</ul>
				<ul class="nav nav-sidebar">
					<li><a
						href="${pageContext.request.contextPath}/UserServlet?op=queryPage">用户管理</a>
					</li>
					<li class="active"><a href="">新增用户</a></li>
					<li><a href="EmpServlet?op=queryPage">员工管理</a></li>
					<li><a href="">Another nav item</a></li>
					<li><a href="">More navigation</a></li>
				</ul>
				<ul class="nav nav-sidebar">
					<li><a href="">Nav item again</a></li>
					<li><a href="">One more nav</a></li>
					<li><a href="">Another nav item</a></li>
				</ul>
			</div>
			<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">

				<h2 class="sub-header">请填写要新增的用户</h2>
				<div class="table-responsive">
					<form class="form-horizontal"
						action="${pageContext.request.contextPath}/UserServlet?op=insert"
						method="post">
						<div class="form-group">
							<label for="userName" class="col-sm-2 control-label">用户名</label>
							<div class="col-sm-8">
								<input type="text" required="required" class="form-control"
									name="userName" id="userName" />
							</div>
						</div>
						<div class="form-group">
							<label for="passWord" class="col-sm-2 control-label">密码</label>
							<div class="col-sm-8">
								<input type="password" required="required" class="form-control"
									name="passWord" id="passWord" />
							</div>
						</div>
						<div class="form-group">
							<label for="userSex" class="col-sm-2 control-label">性别</label>
							<div class="col-sm-1">
								<select class="form-control" name="userSex" id="userSex">
									<option value="男">男</option>
									<option value="女">女</option>
								</select>
							</div>
						</div>

						<div class="form-group">
							<label for="userTel" class="col-sm-2 control-label">手机号码</label>
							<div class="col-sm-8">
								<input type="tel" required="required" class="form-control"
									name="userTel" id="userTel" />
							</div>
						</div>
						<div class="form-group">
							<label for="userAdress" class="col-sm-2 control-label">居住地址</label>
							<div class="col-sm-8">
								<input type="text" required="required" class="form-control"
									name="userAdress" id="userAdress" />
							</div>
						</div>

						<div class="form-group">
							<div class="col-sm-offset-5 col-sm-1">
								<button type="submit" onclick="myFun()" style="width: 100px;"
									class="btn btn-danger">提交</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<div class="modal fade mtmst" id="modal-container-27331" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div style="z-index: 10000;" class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-hidden="true">×</button>
						<div id="loginSucess" style="display: none;">登入成功，请关闭窗口</div>
						<form id="formLogin" class="form-signin" method="post"
							onsubmit="return check()">
							<h2 class="form-signin-heading">请登录</h2>
							<div id="msg" style="display: none;">用户名或密码错误</div>
							<label for="userNameLogin" class="sr-only">用户名</label> <input
								type="text" id="userNameLogin" name="userNameLogin"
								class="form-control" placeholder="用户名" required autofocus>
							<label for="passWordLogin" class="sr-only">密码</label> <input
								type="password" id="passWordLogin" name="passWordLogin"
								class="form-control" placeholder="密码" required>
							<div class="checkbox">
								<label> <input type="checkbox" value="remember-me">
									记住我
								</label>
							</div>
							<a><button id="btnlogin"
									class="btn btn-lg btn-primary btn-block" type="button">登录</button></a>
						</form>
					</div>
				</div>

			</div>
		</div>
	</div>
	<script src="layer.js"></script>
	<script type="text/javascript">
		$(function() {
			//登录的点击事件
			$("#btnlogin").click(function() {
				//ajax请求
					$.ajax({
						url : "${pageContext.request.contextPath}/UserServlet?op=login",//url地址
						type : "post",//请求类型
						data : {
							   "userNameLogin" : $('#userNameLogin').val(),
							   "passWordLogin" : $('#passWordLogin').val()
							   },//传递的数据
							   //成功后做到事
							   success : function(data) {
								   //判断返回值
									if (data == "账号或密码错误") {
										//设置css样式
										$("#msg").css("display","block");
										$("#msg").css("color","red");
									} else {
										//设置css样式
										$("#btnLo").css("display","none");
										$("#btnExit").css("display", "block");
										$("#imfor").text("欢迎" + data + "登录");
										$("#imfor").css("color","blue");
										$("#loginSucess").css("display", "block");
										$("#formLogin").css("display", "none");
										request.setAttribute(
												"data", data);
										}
									}
						});
			});

		});
	</script>
</body>

</html>